package com.woniu.atms.controller.aft;

import com.woniu.atms.entity.G5Car;
import com.woniu.atms.entity.G5CarSeat;
import com.woniu.atms.entity.G5CarType;
import com.woniu.atms.mapper.CarSeatDao;
import com.woniu.atms.service.CarSeatService;
import com.woniu.atms.util.Code;
import com.woniu.atms.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * @author 张奇
 * @title: AftSeatController 座位管理
 * @projectName g5_atms
 * @description:  座位管理
 * @date 2022/1/17 15:36
 */
@Api(tags = "后台座位管理")
@RestController
@RequestMapping("/api/aft/v1/seat")
public class AftSeatController {


    @Resource
    private CarSeatService carSeatService;
    /**
     * 根据车辆id给具体的车辆添加座位，根据车辆类型里的座位数量，将座位全部添加
     * @return
     */
    @ApiOperation(value = "根据车辆id添加所有座位",notes = "根据车辆id添加所有座位")
    @RequestMapping("/add/{carId}")
    public ResponseResult<Void> addSeat(@PathVariable("carId") Integer carId){

        boolean flag= carSeatService.addListByCarId(carId);
        if(flag){
            return ResponseResult.SUCCESS;
        }else {
            return ResponseResult.FAIL;
        }
    }

    /**
     * 根据车辆id查询该车所有座位
     * @param carId
     * @return
     */
    @ApiOperation(value = "根据车辆id查询所有座位",notes = "根据车辆id查询所有座位")
    @RequestMapping("/list/{carId}")
    public ResponseResult<List> seatList(@PathVariable("carId") Integer carId){
        List<G5CarSeat> seats = carSeatService.seatList(carId);
        return new ResponseResult<>(Code.SUCCESS, "查询成功", seats);
    }

    /**
     *修改座位状态
     * @param carSeat 前端传入id 和 status
     * @return
     */
    @ApiOperation(value = "修改座位信息",notes = "修改座位信息，参数 座位id,座位状态")
    @RequestMapping("/status")
    public ResponseResult<Void> updateSeatStatus(@RequestBody G5CarSeat carSeat){
        boolean row = carSeatService.update(carSeat);
        if(row){
            return ResponseResult.SUCCESS;
        }else {
            return ResponseResult.FAIL;
        }
    }

}
